<template>
  <div>
    <line-chart-style :height="height"
                      :optionSeries="optionSeriesCommunicationAnalysis"
                      :optionXAxisData="optionXAxisDataCommunicationAnalysis"
                      :optionTitleText="optionTitleTextCommunicationAnalysis"
                      :optionLegend="optionLegendCommunicationAnalysis"
                      :saveImage="true"
                      @getBase64Image="getBase64Image"
    />
  </div>
</template>
<script>
  import {
    getMediaNameTrend,
  } from "@/api/system/reportGenerate";
  import LineChartStyle from '@/components/Echarts/LineChartStyle'

export default {
  props: {
    eventId: {
        type: Number,
        default: 0
      },
    height: {
      type: String,
      default: '340px'
    },

  },
  data() {
    return {
      optionSeriesCommunicationAnalysis: [],
      optionXAxisDataCommunicationAnalysis: [],
      optionLegendCommunicationAnalysis: [],
      optionTitleTextCommunicationAnalysis: '',
      loading: true,

    }
  },
  components:{
    LineChartStyle,
  },
  computed: {
  },
  watch: {},
  mounted() {
    this.getMediaNameTrend()
  },
  created() {

  },
  methods: {
    getBase64Image(val) {
      this.$emit('getBase64Image', val)
    },

    getMediaNameTrend() {
      this.loading = true;
      console.log(this.eventId)
      getMediaNameTrend(this.eventId).then(response => {
        this.loading = false;
        //正负面信息趋势图
        let communicationAnalysis = response.data.linkedHashMap
        this.optionTitleTextCommunicationAnalysis = ''
        let types= new Set()
        communicationAnalysis.forEach(item=>{
          this.optionXAxisDataCommunicationAnalysis.push(item.name)
          item.value.forEach(v=>{
            types.add(v.name)
          })
        })
        console.log("types:",types)
        types.forEach((item, index) => {
          let customDataItem = {
            data: [],
            type: 'line',
            symbol: 'diamond',
            symbolSize: 20,
            lineStyle: {
              color: '#ffffff',
              width: 4,
              type: 'dashed'
            },
          }
          let d = [];
          this.optionXAxisDataCommunicationAnalysis.forEach(day=>{
            let obj={
              value:0,
              label: {
                normal: {
                  formatter: '',
                  show: true,
                }
              }
            }
            let dayValue
            communicationAnalysis.forEach(v=>{
               if(day===v.name){
                 dayValue=v.value
               }
            })
            dayValue.forEach(v=>{
              if(item===v.name){
                obj.value=v.value
                if(v.value>0){
                  obj.label.normal.formatter=item
                }
              }
            })
            d.push(obj)
          })
          customDataItem.data = d
          customDataItem.name = item
          this.optionSeriesCommunicationAnalysis.push(customDataItem)
        })
      });
    },

  }
}
</script>

